﻿<%@ Control Language="VB" AutoEventWireup="false" CodeFile="CartSummary.ascx.vb" Inherits="CartSummary" %>
<div class="viewcart">
    <asp:ObjectDataSource ID="odsViewCart" runat="server"  
        SelectMethod="GetCart" DeleteMethod="RemoveItem" TypeName="UserCart">
            <DeleteParameters>
                <asp:Parameter Name="RowNumber" Type="Int32" />
            </DeleteParameters>
        </asp:ObjectDataSource>
    <asp:GridView CssClass="Gridview" ID="gvwCartList" 
        DataKeyNames="RowNumber" ShowFooter="True" AutoGenerateColumns="False" 
        runat="server" DataSourceID="odsViewCart">
        <Columns>
            <asp:TemplateField ItemStyle-Width="75px" HeaderText="Product #">
                <ItemTemplate>
                    <center>
                        <asp:Label ID="lblID" runat="server" Text='<%# Bind("ID") %>' />
                        <asp:Label ID="lblRow" Visible="false" runat="server" Text='<%# Bind("RowNumber") %>' />
                    </center>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Product Detail">
                <ItemTemplate>
                    <table style="margin:1px;" width="100%">
                        <tr>
                            <td align="left" style="width:25%; padding:2px;">
                                <asp:Image Visible='<%# (Not ReadOnlyMode)%>' Width="75%" ID="imgProd" AlternateText='<%# Bind("Name") %>' ImageUrl='<%# Bind("ImagePath") %>' runat="server" />
                            </td>
                            <td>
                                <asp:Label ID="lblName" runat="server" Text='<%# Bind("Name") %>'></asp:Label><br />
                                <asp:Label ID="lblDesc" runat="server" Text='<%# Bind("Desc") %>'></asp:Label><br />
                                <asp:Panel ID="pnlDetailRead" runat="server" Visible='<%# ReadOnlyMode AndAlso Eval("CanPersonalize") %>' >
                                    Personalize Text:
                                    <asp:Label ID="lblComment" runat="server" Text='<%# Bind("Comment") %>'></asp:Label><br />
                                </asp:Panel>
                                <asp:Panel ID="pnlDetailEdit" runat="server" Visible='<%# (Not ReadOnlyMode) AndAlso Eval("CanPersonalize") %>' >
                                    Personalize: &nbsp;<asp:CheckBox OnCheckedChanged="chkPersonalize_Changed" AutoPostBack="true" Visible='<%# Bind("CanPersonalize") %>' Checked='<%# Bind("Personalize") %>' ID="chkPersonalize" runat="server" />
                                    <asp:TextBox Enabled='<%# Bind("Personalize") %>' Visible='<%# Bind("CanPersonalize") %>' ID="txtComment" MaxLength="10" runat="server" Text='<%# Bind("Comment") %>'/>
                                </asp:Panel>
                            </td>
                        </tr>
                    </table>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField FooterStyle-HorizontalAlign="Right" ItemStyle-Width="75px" HeaderText="Qty">
                <ItemTemplate>
                    <asp:Panel ID="pnlQtyRead" runat="server" Visible='<%# ReadOnlyMode %>' >
                        <asp:Label ID="lblQty" runat="server" Text='<%# Bind("Qty") %>'/>
                    </asp:Panel>
                    <center>
                    <asp:Panel ID="pnlQtyEdit" runat="server" Visible='<%# Not ReadOnlyMode %>' >
                        <asp:TextBox ID="txtQty" Width="25px" MaxLength="2" runat="server" Text='<%# Bind("Qty") %>'></asp:TextBox>
                        <asp:RequiredFieldValidator ControlToValidate="txtQty" ID="vldReqtxtQty" runat="server" Display="None" ErrorMessage="Qty required" />
                        <ajaxToolkit:ValidatorCalloutExtender ID="vldReqtxtQty_ValidatorCalloutExtender" 
                            runat="server" Enabled="True" TargetControlID="vldReqtxtQty"/>
                        <asp:RangeValidator ControlToValidate="txtQty" Type="Integer" MinimumValue="1" MaximumValue="99" ID="vldRantxtQty" runat="server" Display="None" ErrorMessage="Qty 1 - 99 allowed"/>
                        <ajaxToolkit:ValidatorCalloutExtender ID="vldRantxtQty_ValidatorCalloutExtender" 
                            runat="server" Enabled="True" TargetControlID="vldRantxtQty"/>
                    </asp:Panel>
                    </center>
                </ItemTemplate>
                <FooterTemplate>
                    <b>Total:&nbsp;</b>
                </FooterTemplate>
            </asp:TemplateField>
            <asp:TemplateField ItemStyle-Width="125px" HeaderText="Amount">
                <ItemTemplate>
                    <center>
                        $<asp:Label ID="lblAmount" runat="server" Text='<%# Eval("Qty") * Eval("Amount") %>'/>
                    </center>
                </ItemTemplate>
                <FooterTemplate>
                    <center>
                        $<asp:Label ID="lblSum" runat="server" Text='<%# GetSum() %>'/>
                    </center>
                </FooterTemplate>
            </asp:TemplateField>
            <asp:TemplateField ItemStyle-Width="100px" ShowHeader="False">
                <ItemTemplate>
                    <asp:LinkButton Visible='<%# Not ReadOnlyMode %>' ID="btnDelete" runat="server" CausesValidation="False" CommandName="Delete" Text="Remove"/>
                </ItemTemplate>
                <FooterTemplate>
                    <asp:Button Visible='<%# Not ReadOnlyMode %>' OnClick="btnUpdateTotal_Click" ID="btnUpdateTotal" runat="server" Text="Re-Calculate" />
                </FooterTemplate>
            </asp:TemplateField>
        </Columns>
        <EmptyDataTemplate>
            <center>
                No items in cart.  Please add a product.
            </center>
        </EmptyDataTemplate>
</asp:GridView>
<br />
<center>
    <asp:Button ID="btnCheckout" runat="server" Text="Checkout" />
</center>
<br />
</div>